package com.shunwang.errors.client.listener;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.shunwang.errors.errorinfo.ErrorInfo;
import com.shunwang.errors.errorinfo.ErrorLogger;

public class ErrorLoggerContentListener implements HttpSessionListener {

	private final static ErrorLogger errors = ErrorLogger.getInstance();
	
	public void sessionCreated(HttpSessionEvent event) {
		if(event.getSession().getServletContext().getAttribute(ErrorInfo.Ident) == null){
			event.getSession().getServletContext().setAttribute(ErrorInfo.Ident, errors.getInfo());
		}
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		if(event.getSession().getServletContext().getAttribute(ErrorInfo.Ident) != null){
			event.getSession().getServletContext().removeAttribute(ErrorInfo.Ident);
			errors.removeInfo();
		}
	}

}
